package com.example.poc;

import java.util.List;

import org.springframework.stereotype.Component;

import com.example.poc.query.FilterRequest;
import com.example.poc.query.SearchRequest;
import com.example.poc.query.SortRequest;

@Component
public class Commons {

  public SearchRequest createSearchRequest(FilterRequest filterRequest, SortRequest sortRequest, int page, int size) {
    SearchRequest searchRequest = new SearchRequest();
    searchRequest = new SearchRequest();
    if (filterRequest != null) {
      List<FilterRequest> filterRequestList = searchRequest.getFilters();
      filterRequestList.add(filterRequest);
      searchRequest.setFilters(filterRequestList);
    }
    if (sortRequest != null) {
      List<SortRequest> sortRequestList = searchRequest.getSorts();
      sortRequestList.add(sortRequest);
      searchRequest.setSorts(sortRequestList);
    }
    searchRequest.setPage(page);
    searchRequest.setSize(size);
    return searchRequest;
  }

}
